import { Response } from "express";
import { ErrResp, SuccResp } from "../common/types/resp";

/**
 * 成功响应
 * @param res 
 * @param options 
 */
export const success = <T>(res: Response, options: SuccResp<T>) => {
    const { msg, data='' } = options;
    res.json({ code: 1, msg: msg, data })
}

/**
 * 失败的响应体
 * @param res 
 * @param options 
 */
export const error = (res: Response, options: ErrResp) => {
    res.json({code: -1, msg: options.msg})
}